const app = getApp();
var time = require("../../../utils/util.js");
Page({
  data: {
    head: 'LOST',
    content:'',
    time:'',
    title:'',
    loading:false,
    currentPage:1,
    pageSize:6,
    scrollTop: 0,
    lost:[
    ],
  },
onLoad: function (options) {
    var that = this;
    wx.request({
      url: app.globalData.urlPath + "getLostFoundList.action", //仅为示例，并非真实的接口地址
      data: {
      },
      success: function (res) {
        console.log(res.data)
        for (var i = 0; i < res.data.length; i++) {
          res.data[i]["createTime"] = time.formatTime(res.data[i]["createTime"] / 1000, 'Y/M/D');
        }
        that.setData({
          lost: res.data,
          currentPage:that.data.currentPage+1,
        })
      },
    })

  },

  /**
   * 转到详细页面
   */
  toLostDetail:function(e){
    var that = this;
    var lostId = e.currentTarget.dataset.lostid;
    // wx.navigateTo({
    //   url: '/pages/lost/lostDetail/lostDetail?lostId=' + lostId,
    // })
    console.log(lostId);
  },

  /**
   * 前往发布
   */
  toPublish:function(e){
    var that = this;
    wx.navigateTo({
      url: '/pages/lost/lost_found/lost_found',
    })
  },

   //   该方法绑定了页面滑动到底部的事件
    bindDownLoad: function () {
    var that = this;
    GetList(that);
  },
  //   该方法绑定了页面滚动时的事件
  scroll: function (event) {
    this.setData({
      scrollTop: event.detail.scrollTop
    });
  },
  onReachBottom: function () {
    var that = this;
    var data = that.data;

    wx.showNavigationBarLoading() //在标题栏中显示加载
    wx.request({
      url: app.globalData.urlPath + 'getLostFoundList.action',
      data: {
        currentPage: that.data.currentPage,
      },
      success: function (res) {
        var pageSize = that.data.pageSize;
        if (res.data.length < that.data.pageSize)
          pageSize = res.data.length

        if (res.data.length === 0) {
          wx.showToast({
            title: '无更多数据',
            icon: 'none',
          })
          return
        };

        setTimeout(() => {
          that.setData({
            loading: false,
            lost: data.lost.concat(res.data),
            currentPage: that.data.currentPage + 1, //currentPage增加1
          })
        }, 2000)
      },
    })
  },
})